package com.sky.config;

import io.lettuce.core.dynamic.RedisCommandFactory;
import org.aspectj.weaver.ast.Var;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import javax.xml.transform.Templates;

// 配置类
@Configuration
public class RedisTemplateConfiguration {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
        // 创建自己的配置类,然后交给IOC容器
        RedisTemplate template = new RedisTemplate();

        // 必须设置连接工程
        template.setConnectionFactory(factory);

        // key显示好看一些,就需要设置key的序列化器
        // 只对String\list\set\zset 生效
        template.setKeySerializer(new StringRedisSerializer());
        // template.setValueSerializer(new StringRedisSerializer());

        // 对Hash生效
        template.setHashKeySerializer(new StringRedisSerializer());
        // template.setHashValueSerializer(new StringRedisSerializer());

        // 返回template
        return template;
    }

}
